package com.imooc.consumer;

import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

/**
 * 广播模式（MessageModel.BROADCASTING）:每个消费者，都会消费消息
 * 集群模式（MessageModel.CLUSRERING):默认，每一个消费，只会被某一个消费者消费一次
 * 消费端接受消息，默认是多线程，单线程顺序消息要改成：ConsumeModel.ORDERLY
 */
@RocketMQMessageListener(topic = "myrocketmq", consumerGroup = "${rocketmq.producer.group}", messageModel = MessageModel.CLUSTERING, consumeMode = ConsumeMode.ORDERLY)
@Service
public class ConsumerService implements RocketMQListener<String> {

    @Override
    public void onMessage(String s) {
        System.out.println("接受消息：" + s);
    }
}
